Lab 10

Program Design

CS211 Lab Policy:

Instructions:

For this lab you must design and create a program that finds a root of an equation using a method known as the secant method. Store your final solution in a file called lab10.m. Please follow the following steps:

  1. Understand the problem.  Read the description of the secant method below. Before proceeding to the next step, make sure you fully understand the problem. Do not hesitate to ask your instructor for clarifications on anything that is not clear.
     
  2. Design a solution.  Write a pseudocode algorithm to solve this problem.  Type your pseudocode algorithm into your lab10.m file. After you are finished with your pseudocode algorithm, "comment out" the algorithm text.
     
  3. Translate your solution into a program.  Write MATLAB code that will implement your algorithm and include the code in you lab10.m file. Use the example program from Lab 7 as a guide to how to create your Lab10 function.
     
  4. Test and debug your program.  Thoroughly test your program on a variety of inputs.  This includes changing the equation that you are finding the roots of. Fix any errors you discover.
     
  5. Extra work (not required). The secant method will fail if the slope of the tangent goes to zero or the equation has no real roots. Add a counter to the loop that counts the number of iterations of the loop and, if the loop executes more than 200 times, stop the loop and report that no real root exists.
     

The secant method for finding a root of an equation:

The secant method for finding a root of an equation is similar to the Newton-Raphson method, but it does not require an exact equation for the derivative of the equation. Instead, it approximates the derivative using points along the curve. As you read the following description, refer to the figure below. Starting from an initial guess value for a root, the slope of the curve tells us which direction to move towards the x axis. We can approximate the slope of the curve by using another point along the curve that is a small distance away from the guess. From these points, we can form two equations for the slope of the tangent line:

Now set these two equations for the tangent's slope equal to each other and solve for the "NewGuess" value:

If the above equation is repeatedly calculated, each "new guess" value will get closer and closer to a root value.

Turn-in:

Submit your lab10.m file.

References: (none)